package com.yilin.medical.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.yilin.medical.R;

/**
 * 会诊首页
 * @author lijianqun
 *
 */
public class HuiZhenHomeActivity extends BaseActivity implements OnItemClickListener{


	private GridView mGridViewHome;
	private Context context;
	private String[] titles = {"病例讨论","视频会诊","国际/国内转诊"};
	//会诊图片  病例讨论      视频讨论     国际国内 /转诊
	int[] homeItemIds = { R.drawable.page,
			R.drawable.page, R.drawable.page };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewWithTitle(R.layout.activity_home_huizhen);
		context = this;
		initView();
		registener();
	}

	private void initView() {
		mGridViewHome = (GridView) findViewById(R.id.gv_home);
		mGridViewHome.setAdapter(new MyGridAdapter(context, homeItemIds));
		mTitle.getTitle().setText("会诊");
	}

	private void registener() {
		mGridViewHome.setOnItemClickListener(this);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {

		}
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {

		Intent intent ;
		switch (position) {
		//TODO 需要修改 
		case 0:
			//病例讨论 
			intent = new Intent(context, BingLiTaoLunActivity.class);
			startActivity(intent);
			break;
		case 1:
			//视频讨论
			intent = new Intent(context, ShiPinHuiZhenActivity.class);
			startActivity(intent);
			break;
		case 2:
			//国际国内 /转诊
			intent = new Intent(context, GuoJiGuoNeiZhuanZhenActivity.class);
			startActivity(intent);
			break;
		}
	
	}

	public class MyGridAdapter extends BaseAdapter {
		private Context context;
		private int[] imageId;
		
		
		public MyGridAdapter(Context context, int[] imageId) {
			super();
			this.context = context;
			this.imageId = imageId;
		}


		@Override
		public int getCount() {
			return imageId.length;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view = View.inflate(context,
					R.layout.griditem_home_, null);
			ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_home);
			TextView tv_item = (TextView) view.findViewById(R.id.tv_item);
			iv_icon.setImageResource(imageId[position]);
			tv_item.setText(titles[position]);

			return view;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

	}

}
